import mongoose from "mongoose";
import uniqueValidator from "mongoose-unique-validator";

const messageScheme = new mongoose.Schema(
  {
    senderId: {
      type: mongoose.Schema.Types.ObjectId,
      ref: "User",
      required: true,
    },
    receiverId: {
      type: mongoose.Schema.Types.ObjectId,
      ref: "User",
      required: true,
    },
    message: {
      type: String,
      required: true,
    },
  },
  { timestamps: true },
);

messageScheme.plugin(uniqueValidator, { message: "is already taken" });
const Message =
  mongoose.models.Message || mongoose.model("Message", messageScheme);

export default Message;
